home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / yahoo / yahoologinsocket.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  6KB  |  166 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from logging import getLogger
  5. from yahoo.YahooSocket import DEFAULT_YMSG_VERSION
  6. from yahoo.yahooutil import from_ydict
  7. from yahoo.yahooutil import YahooLoginError
  8. from util.threads import threaded
  9. from yahoo.login import yahoo_v15_auth, yahoo64, YahooRateLimitException, YahooAuthException
  10. from hashlib import md5
  11. from yahoo.yahooutil import to_ydict
  12. from yahoo.YahooSocket import YahooSocket
  13. import common
  14. log = getLogger('YahooLoginSocket')
  15.  
  16. class YahooLoginSocket(YahooSocket):
  17.     
  18.     def __init__(self, yahoo, server):
  19.         YahooSocket.__init__(self, yahoo, server)
  20.         log.info('connecting to %s with user: %s', self.server, self.yahoo.username)
  21.         
  22.         def onfail(exc = (None,)):
  23.             self.yahoo.set_disconnected(self.yahoo.Reasons.CONN_FAIL)
  24.             self.close()
  25.  
  26.         self.connect(self.server, error = onfail)
  27.         if not self.readable():
  28.             onfail()
  29.         
  30.  
  31.     
  32.     def logon(self):
  33.         y = self.yahoo
  34.         
  35.         def fail(exc = (None,)):
  36.             y.set_disconnected(y.Reasons.CONN_FAIL)
  37.  
  38.         user = y.username
  39.         password = y.password
  40.         log.info('logging in %s', user)
  41.         y.change_state(y.Statuses.AUTHENTICATING)
  42.         yield self.gsend('auth', 'custom', {
  43.             1: user }, v = DEFAULT_YMSG_VERSION)
  44.         yield self.gwait('auth', 'brb', self.logon_err)
  45.         (hdr, data) = None
  46.         auth_challenge = from_ydict(data)
  47.         if '94' not in auth_challenge:
  48.             log.warning('auth challenge packet did not have challenge str (94): %r', auth_challenge)
  49.             fail()
  50.             return None
  51.         
  52.         challenge_str = auth_challenge['94']
  53.         threaded(yahoo_15_weblogin)(y, user, password, challenge_str, error = fail)
  54.  
  55.     
  56.     def logon_err(self):
  57.         y = self.yahoo
  58.         y.set_disconnected(y.Reasons.CONN_FAIL)
  59.         self.close()
  60.  
  61.     
  62.     def generic_error(self):
  63.         y = self.yahoo
  64.         y.set_disconnected(y.Reasons.CONN_FAIL)
  65.  
  66.     
  67.     def chatlogon(self, sv, st, data):
  68.         
  69.         def gen(sv, st, data):
  70.             me = self.yahoo.self_buddy.name
  71.             yield self.gsend('chatonline', 'available', to_ydict({
  72.                 '1': me,
  73.                 '109': me,
  74.                 '6': 'abcde' }))
  75.             yield self.gwait('chatonline', 'brb', self.generic_error)
  76.             yield self.gsend(sv, st, data)
  77.  
  78.         self.async_proc(gen(sv, st, data))
  79.  
  80.     
  81.     def conflogon(self, roomname, callback):
  82.         
  83.         def gen():
  84.             me = self.yahoo.self_buddy.name
  85.             yield self.gsend('conflogon', 'available', to_ydict({
  86.                 '1': me,
  87.                 '3': me,
  88.                 '57': roomname }))
  89.             yield self.gwait('conflogon', 'brb', self.generic_error)
  90.             YahooConf = YahooConf
  91.             import yahoo.YahooConversation
  92.             conf = self.yahoo.conferences.setdefault(roomname, YahooConf(self.yahoo, roomname))
  93.             conf.buddy_join(self.yahoo.self_buddy)
  94.             callback(conf)
  95.  
  96.         self.async_proc(gen())
  97.  
  98.     
  99.     def handle_connect(self):
  100.         log.info('Yahoo Socket connected to %s:%d', *self.server)
  101.         self.async_proc(self.logon())
  102.  
  103.     
  104.     def handle_close(self):
  105.         log.critical('handle_close')
  106.         if self.yahoo.offline_reason == self.yahoo.Reasons.NONE:
  107.             rsn = self.yahoo.Reasons.CONN_LOST
  108.         else:
  109.             rsn = self.yahoo.offline_reason
  110.         self.yahoo.set_disconnected(rsn)
  111.         self.close()
  112.         self.yahoo = None
  113.  
  114.     
  115.     def handle_error(self, *a, **k):
  116.         import traceback as traceback
  117.         traceback.print_exc()
  118.         log.error('handle_error')
  119.         if self.yahoo:
  120.             self.yahoo.set_disconnected(self.yahoo.Reasons.CONN_LOST)
  121.         
  122.         common.socket.handle_error(self, *a, **k)
  123.  
  124.     
  125.     def handle_expt(self):
  126.         log.error('handle_expt: out-of-band data')
  127.         self.yahoo.set_disconnected(self.yahoo.Reasons.CONN_LOST)
  128.         self.close()
  129.         self.yahoo = None
  130.  
  131.  
  132.  
  133. def yahoo_15_weblogin(y, user, password, challenge_str):
  134.     
  135.     try:
  136.         (crumb, yc, t, jar) = yahoo_v15_auth(challenge_str, password, user)
  137.     except YahooRateLimitException:
  138.         return y.set_disconnected(y.Reasons.RATE_LIMIT)
  139.     except YahooAuthException:
  140.         return y.set_disconnected(y.Reasons.BAD_PASSWORD)
  141.  
  142.     y.cookies.update(Y = yc.split()[0][:-1], T = t.split()[0][:-1])
  143.     y.jar = jar
  144.     crumbchallengehash = yahoo64(md5(crumb + challenge_str).digest())
  145.     log.info('logging on with initial status %s', y.initial_status)
  146.     (None, None, None, None, common.netcall)((lambda : y.send('authresp', y.initial_status, [
  147. 'ycookie',
  148. yc,
  149. 'tcookie',
  150. t,
  151. 'crumbchallengehash',
  152. crumbchallengehash,
  153. 0,
  154. user,
  155. 'identity',
  156. user,
  157. 1,
  158. user,
  159. 'mystery_login_num',
  160. '2097087',
  161. 'version_str',
  162. '8.1.0.421',
  163. 148,
  164. '300'])))
  165.  
  166.